/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package net.worlds.lua.metatable;

import net.worlds.TraceResult;
import se.krka.kahlua.vm.JavaFunction;
import se.krka.kahlua.vm.LuaCallFrame;


public class TraceResultMetatable {
    public static class TraceResultIndex implements JavaFunction
    {
        public int call(LuaCallFrame callFrame, int nArguments) {
            synchronized(callFrame.thread.state.getEnvironment())
            {
                try {
                    TraceResult trace = (TraceResult) callFrame.get(0);
                    String k = (String) callFrame.get(1);
                    if(k.equals("part"))
                        callFrame.push(trace.part);
                    else if(k.equals("start"))
                        callFrame.push(trace.start);
                    else if(k.equals("position"))
                        callFrame.push(trace.end);
                    else if(k.equals("distance"))
                        callFrame.push(trace.distanceVec);
                    else
                    {
                            throw new RuntimeException(k + " is not a member of TraceResult");
                    }
                    return 1;
                } catch (Exception ex) {
                    throw new RuntimeException(ex.toString());
                }
            }
        }
        @Override
        public String toString()
        {
            return "Object.newIndex";
        }
    }
}
